import socket
import time


def client(mode = "UDP", addr = ('0.0.0.0', 7788), data = None, defa = True):
	if mode == 'TCP'or mode == 'tcp':
		tcp_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		tcp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
		tcp_sock.connect(addr)
		time.sleep(0.3)
		if defa is True:
			if type(data) is bytes:
				tcp_sock.send(data, addr)
			else:
				tcp_sock.send(data.encode('utf-8'), addr)
		elif defa is False:
			return tcp_sock

	elif (mode == 'UDP') or (mode == 'udp'):
		udp_sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
		print("link complete... ")
		time.sleep(0.7)
		if defa is True:
			if type(data) is bytes:
				udp_sock.sendto(data, addr)
			else:
				udp_sock.sendto(data.encode('utf-8'), addr)
		elif defa is False:
			return udp_sock

